package com.hlcl.huaji.server;

import android.os.Handler;
import android.util.Log;

import com.elcl.network.AppConstant;
import com.elcl.network.AppContext;
import com.elcl.network.OkHttp;
import com.squareup.okhttp.FormEncodingBuilder;

/**
 * Created by lichunlin on 2018/3/12.
 */

public class OrderServer {

    public static OrderServer orderServer;

    public static OrderServer getInstance() {
        if (null == orderServer) {
            orderServer = new OrderServer();
        }
        return orderServer;
    }

    //获取配置信息的server
    public void getConfingServer(Handler handler) {
        String url = IP.IP + "/confing";
        OkHttp.getInstance().get(url, handler, NetCode.ID_CONFING);
    }

    //登录
    public void loginServer(Handler handler, String username, String pwd) {
        String url = IP.IP + "/user/login";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("username", username);
        builder.add("pwd", pwd);

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_LOGIN, "正在登陆");
    }

    //获取用户信息的server
    public void getUserInfoServer(Handler handler) {
        String url = IP.IP + "/user/userinfo";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("userId", AppContext.getUid() + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_USERINFO);
    }

    //获取订单list的server
    public void getOrderListServer(Handler handler, int orderType, int pageNo) {
        String url = IP.IP + "/order/list";
        Log.i("tag", AppContext.getUid() + "aaa" + orderType);
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("userId", AppContext.getUid() + "");
        builder.add("orderType", "" + orderType);
        builder.add("pageNo", pageNo + "");
        builder.add("pageSize", AppConstant.PAGE_SIZE + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_ORDER_LIST);
    }

    //获取订单detail的server
    public void getOrderDetailServer(Handler handler, String orderId) {
        String url = IP.IP + "/order/detail";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("orderId", orderId);

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_ORDER_DETAIL);
    }

    //修改订单状态的server
    public void modifyOrderServer(Handler handler, String orderId, int orderState) {
        String url = IP.IP + "/order/orderStateChange";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("orderId", orderId);
        builder.add("orderState", orderState + "");
        builder.add("userId", AppContext.getUid() + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_ORDER_MODIFY_STATE);
    }

    //获取个人中心订单的数量
    public void getMineOrderNumber(Handler handler) {
        String url = IP.IP + "/order/orderNumber";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("userId", AppContext.getUid() + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_ORDER_NUMBER);
    }

    //获取个人中心我的标签
    public void getMineLabel(Handler handler) {
        String url = IP.IP + "/user/getmylabels";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("userId", AppContext.getUid() + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_LABEL_NUMBER);
    }

    //获取评价的标签
    public void getConfingLabel(Handler handler) {
        String url = IP.IP + "/label";

        OkHttp.getInstance().get(url, handler, NetCode.ID_LABEL_GET);
    }

    //修改地址的接口
    public void modifyAddress(Handler handler, String user_name, String phone, String adress) {
        String url = IP.IP + "/user/modifyAddr";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("user_name", user_name);
        builder.add("phone", phone);
        builder.add("adress", adress);
        builder.add("user_id", AppContext.getUid() + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_MODIFY_ADDRESS);
    }

    //修改卡号的接口
    public void modifyCardNo(Handler handler, String card_user_name, String card_name, String card_no) {
        String url = IP.IP + "/user/modifyCardNo";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("card_user_name", card_user_name);
        builder.add("card_name", card_name);
        builder.add("user_id", AppContext.getUid() + "");
        builder.add("card_no", card_no);

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_MODIFYCARD_NO);
    }


    //提现的接口
    public void withDrawServer(Handler handler, String money) {
        String url = IP.IP + "/withdraw";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("money", money);
        builder.add("userId", AppContext.getUid() + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_WITHDRAW);
    }


    //添加评论
    public void addComment(Handler handler, String orderId, int score, String label_id, String label_name,String commentContent) {
        String url = IP.IP + "/comment/engineer/add";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("orderId", orderId);
        builder.add("score", score + "");
        builder.add("label_id", label_id);
        builder.add("label_name", label_name);
        builder.add("userId", AppContext.getUid() + "");
        builder.add("commentContent", commentContent);

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_COMMENT_ADD);
    }


    //获取订单的评论
    public void getOrderComment(Handler handler, String orderId) {
        String url = IP.IP + "/comment/getByOrderId";
        FormEncodingBuilder builder = new FormEncodingBuilder();
        builder.add("orderId", orderId);
        builder.add("userId", AppContext.getUid() + "");

        OkHttp.getInstance().post(url, builder, handler, NetCode.ID_COMMENT_GET);
    }

}
